split a enumerated attribute values

In a module, I have an enumerated object attribute called "Foo". The possible values of this attribute are "x", "y", "z", and "a".

Give a random object in the module, the "Foo" attribute is associated with the values "x", "y" and "a".

Given this code the values get return with a carriage return I believe.

{code}
Object o = current
string theValues = o."Foo"
print theValues""

// return results
x
y
z
{/code}

Is there a given DXL function that would return the attribute value as "x,y,z"? If not, any ideas how I would be able to split the "theValues" string? I can't see with code if there is indeed a carriage return that is splitting the return values or not.
pete.kowalski - Fri Sep 17 20:24:06 EDT 2010

Re: split a enumerated attribute values
pete.kowalski - Fri Sep 17 20:30:03 EDT 2010

For some reason I can't edit my previous post so here is what my original post should have said.
 



In a module, I have an enumerated object attribute called "Foo". The possible values of this attribute are "x", "y", "z", and "a".

Give a random object in the module, the "Foo" attribute is associated with the values "x", "y" and "a".

Given this code the values get return with a carriage return I believe.

 

 

Object o = current
string theValues = o."Foo"
print theValues""
 
// return results
x
y
a



Is there a given DXL function that would return the attribute value as "x,y,a"? If not, any ideas how I would be able to split the "theValues" string? I can't see with using code if there is indeed a carriage return that is splitting the return values or not.

The only idea I can come with is...
1) find the attribute type that is associated with the "Foo" attribute
2) read each attribute type value and put them in a skip list or some other data structure
3) for each value in the data structure in step 2, perform a lot of If conditions on the attribute value for the given object to determine how to represent the attribute value



 

 

Re: split a enumerated attribute values
pete.kowalski - Fri Sep 17 22:57:25 EDT 2010

pete.kowalski - Fri Sep 17 20:30:03 EDT 2010

For some reason I can't edit my previous post so here is what my original post should have said.
 



In a module, I have an enumerated object attribute called "Foo". The possible values of this attribute are "x", "y", "z", and "a".

Give a random object in the module, the "Foo" attribute is associated with the values "x", "y" and "a".

Given this code the values get return with a carriage return I believe.

 

 

Object o = current
string theValues = o."Foo"
print theValues""
 
// return results
x
y
a



Is there a given DXL function that would return the attribute value as "x,y,a"? If not, any ideas how I would be able to split the "theValues" string? I can't see with using code if there is indeed a carriage return that is splitting the return values or not.

The only idea I can come with is...
1) find the attribute type that is associated with the "Foo" attribute
2) read each attribute type value and put them in a skip list or some other data structure
3) for each value in the data structure in step 2, perform a lot of If conditions on the attribute value for the given object to determine how to represent the attribute value



 

 

Figured it out.

There are indeed newlines. sonicman made a post about newlines and even provided a regular expression to catch them here: https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14289564&#14289564

Re: split a enumerated attribute values
llandale - Tue Sep 21 09:36:12 EDT 2010

pete.kowalski - Fri Sep 17 20:30:03 EDT 2010

For some reason I can't edit my previous post so here is what my original post should have said.
 



In a module, I have an enumerated object attribute called "Foo". The possible values of this attribute are "x", "y", "z", and "a".

Give a random object in the module, the "Foo" attribute is associated with the values "x", "y" and "a".

Given this code the values get return with a carriage return I believe.

 

 

Object o = current
string theValues = o."Foo"
print theValues""
 
// return results
x
y
a



Is there a given DXL function that would return the attribute value as "x,y,a"? If not, any ideas how I would be able to split the "theValues" string? I can't see with using code if there is indeed a carriage return that is splitting the return values or not.

The only idea I can come with is...
1) find the attribute type that is associated with the "Foo" attribute
2) read each attribute type value and put them in a skip list or some other data structure
3) for each value in the data structure in step 2, perform a lot of If conditions on the attribute value for the given object to determine how to represent the attribute value



 

 

I believe regular expressions to be inefficient and tend not to use them. Here's a function that does almost what you want:

Buffer    bufIn=create(), 
        bufOut=create()
//***************************************
string  GetPlainAttr(Object obj, string NameAttr)
{     // Get the Plain attr value turning EOLs into comma-space
        bufOut  = ""
        int     i
        char    c
        for (i=0; i<length(bufIn); i++)
        {
           c    = bufIn[i]
           
           if (c == '\n')
           {  if (i!=length(bufIn)-1)  //-
              then bufOut += ", "     // turn EOL into comma-space
              else{}                   // Ignore trailing EOL
           }
           else bufOut  += c            // export character as-is
        }
        return(stringOf(bufOut))
}     // end GetPlainAttr(Object)

 

 

  • Louie

 

 

Re: split a enumerated attribute values
Mathias Mamsch - Tue Sep 21 10:03:54 EDT 2010

llandale - Tue Sep 21 09:36:12 EDT 2010

I believe regular expressions to be inefficient and tend not to use them. Here's a function that does almost what you want:

Buffer    bufIn=create(), 
        bufOut=create()
//***************************************
string  GetPlainAttr(Object obj, string NameAttr)
{     // Get the Plain attr value turning EOLs into comma-space
        bufOut  = ""
        int     i
        char    c
        for (i=0; i<length(bufIn); i++)
        {
           c    = bufIn[i]
           
           if (c == '\n')
           {  if (i!=length(bufIn)-1)  //-
              then bufOut += ", "     // turn EOL into comma-space
              else{}                   // Ignore trailing EOL
           }
           else bufOut  += c            // export character as-is
        }
        return(stringOf(bufOut))
}     // end GetPlainAttr(Object)

 

 

  • Louie

 

 

Is it possible that you are missing a "bufIn = obj.NameAttr" in the code? Regular expressions can be used very efficiently when they are created once globally and you are working with complex search patterns or with large strings. For example pure DXL code is much too slow when trying to parse an OLE richtext. You can always use findPlainText but it is not as efficient and fast as a regexp. At least thats my opinion :-) Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: split a enumerated attribute values
pete.kowalski - Wed Sep 22 15:26:47 EDT 2010

Mathias Mamsch - Tue Sep 21 10:03:54 EDT 2010
Is it possible that you are missing a "bufIn = obj.NameAttr" in the code? Regular expressions can be used very efficiently when they are created once globally and you are working with complex search patterns or with large strings. For example pure DXL code is much too slow when trying to parse an OLE richtext. You can always use findPlainText but it is not as efficient and fast as a regexp. At least thats my opinion :-) Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Thanks llandale.

I have to agree with Mathias' view here. Regular expressions can be efficient in some cases, and do recommend that all of them are declared globally as he states. Too bad that only the delete perm was overloaded to support RegEx in DOORS 9.2 and up.